<?php

class Add extends TPage
{
	private $element_manager;
	
	public function onLoad($param)
	{
		parent::onLoad($param);
		$this->element_manager = $this->Application->Modules['requested_elements'];
	}
	
	public function saveButtonClicked($sender, $params)
	{
		if($this->Page->IsValid)
		{
			$result = $this->element_manager->addRequestedElement(
													String::format($this->name->Text),
													StatusManager::$AWAITING_STATUS,
													$this->description_checked->Checked ? $this->description->Text : null,
													null,
													$this->User->getName());
			
			if($result)
			{
				$this->info->Text = '<p>'.Prado::localize('Changes saved').'</p>';
				$this->clearForm();
			}
			else
				$this->info->Text = '<p>'.Prado::localize('Changes not saved').'</p>';
		}
	}
	
	public function clearForm()
	{
		$this->name->Text = '';
		$this->description->Text = '';
		$this->description_checked->Checked = false;
	}
	
}

?>